/**
 * @author JN
 * @Date: 2024-04-19
 * @LastEditTime: 2024-04-20
 * @description 组件大小
 */

import { defineStore } from 'pinia';
import i18n from '@/i18n/index'
/**
 * 定义语言类型
 */
type Lan = 'zh_CN' | 'en_US';

/**
 * 语言状态接口
 */
interface Languages {
    language: Lan;
}

/**
 * 定义语言管理的 store
 */
export const useLanguagesChangeStore = defineStore({
    id: "languagesChange",
    state: (): Languages => ({
        language: 'zh_CN',
    }),
    getters: {
        /**
         * 获取当前语言
         * @returns 当前语言
         */
        getLanguage(): Lan {
            return this.language
        }
    },
    actions: {
        /**
         * 设置语言并更新 i18n 的 locale
         * @param language - 语言代码
         */
        setLanguage(language: Lan) {
            (i18n.global.locale as string) = language;
            (this.language as string) = language
        }
    }
});